/* Jordans serverio.js implementation, from qs */
function Request()
{
	this.action = null;
	this.XML = null;
	this.commInterface = null;

	// Initialise XMLHttpRequest object
	this.resetXMLHR();
	return true;
}




/* Check if the XMLHttpRequest object is available */
Request.prototype.isAvailable = function()
{
	if (this.commInterface == null)
	{
		return false;
	}
	
	return true;
}




/* Execute the action which has been associated with the completion of this object */
Request.prototype.executeAction = function()
{
	// If XMLHR object has finished retrieving the data
	if (this.commInterface.readyState == 4)
	{
		// If the data was retrieved successfully
		try
		{
			if (this.commInterface.status == 200)
			{
				this.responseText = this.commInterface.responseText;
				this.responseBinary = this.commInterface.responseBody;
				this.action();
			}
			// IE returns status = 0 on some occasions, so ignore
			else if (this.commInterface.status != 0)
			{
				//alert("There was an error while retrieving the URL: " + this.commInterface.statusText);
			}
		}
		catch (error)
		{
		}
	}

	return true;
}




/* Return responseText */
Request.prototype.getText = function()
{
	return this.commInterface.responseText;
}




/* Return responseXML */
Request.prototype.getXML = function()
{
	return this.commInterface.responseXML;
}

/* Initialise XMLHR object and load URL */
Request.prototype.loadURL = function(URL, CGI)
{
	this.resetXMLHR();
	this.commInterface.open("GET", URL + '?rnd=' + Math.random() + '&' + CGI);
//	this.commInterface.setRequestHeader('Accept','application/x-core');
	this.commInterface.setRequestHeader("User-Agent", "jordanb-resolve++");

	this.commInterface.send(null);

	return true;
}




/* Turn off existing connections and create a new XMLHR object */
Request.prototype.resetXMLHR = function()
{
	var self = this;
	if (this.commInterface != null && this.commInterface.readyState != 0 && this.commInterface.readyState != 4)
	{
		this.commInterface.abort();
	}

	this.commInterface = null;


	//var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  this.commInterface = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   this.commInterface = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   this.commInterface = null;
	  }
	 }
@end @*/
	if (!this.commInterface && typeof XMLHttpRequest!='undefined') {
		try {
			this.commInterface = new XMLHttpRequest();
		} catch (e) {
			this.commInterface=null;
		}
	}
	if (!this.commInterface && window.createRequest) {
		try {
			this.commInterface = window.createRequest();
		} catch (e) {
			this.commInterface=null;
		}
	}

	if (this.commInterface == null) return false;

	this.commInterface.onreadystatechange = function()
	{
		this._postexec = self._postexec;
		this._process = self._process;
		self.executeAction();

		return true;
	};
 
	return true;
}


/* Assign the function which will be executed once the XMLHR object finishes retrieving data */
Request.prototype.setAction = function(actionFunction)
{
	this.action = actionFunction;

	return true;
}
